<?php

declare(strict_types=1);

namespace App\Request\User;

use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;

class UserPasswordEditRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'id' => [
                'required',
                Rule::exists('users')->where(function ($query) {
                    $query->whereNull('deleted_at');
                }),
            ],
            'password' => 'required|regex:/^(?![\d]+$)(?![a-z]+$)(?![A-Z]+$)(?![!#$%^&*]+$)[\da-zA-Z-!@#$^&+.]{8,32}$/'
        ];
    }

    public function messages(): array
    {
        return [
            'password.regex' => '密码为8-16位数字_字母组成',
        ];
    }

}
